package com.ruoyi.mail.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.ShiroUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.JiajiaMallProductLevel;
import com.ruoyi.system.domain.JiajiaMallProductType;
import com.ruoyi.system.domain.JiajiaMallShopProductInformation;
import com.ruoyi.system.domain.vo.JiajiaMallProductLevelVo;
import com.ruoyi.system.domain.vo.JiajiaMallShopProductInformationVo;
import com.ruoyi.system.service.IJiajiaMallProductLevelService;
import com.ruoyi.system.service.IJiajiaMallProductTypeService;
import com.ruoyi.system.service.IJiajiaMallShopProductInformationService;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 商城产品信息Controller
 * 
 * @author ruoyi
 * @date 2025-03-05
 */
@Controller
@RequestMapping("/mall/product")
public class JiajiaMallShopProductInformationController extends BaseController
{
    private String prefix = "mall/product";

    @Autowired
    private IJiajiaMallShopProductInformationService jiajiaMallShopProductInformationService;

    @Autowired
    private IJiajiaMallProductTypeService jiajiaMallProductTypeService;

    @Autowired
    private IJiajiaMallProductLevelService jiajiaMallProductLevelService;

    @RequiresPermissions("system:product:view")
    @GetMapping()
    public String information()
    {
        return prefix + "/product";
    }

    /**
     * 查询商城产品信息列表
     */
    @RequiresPermissions("system:product:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        startPage();
        List<JiajiaMallShopProductInformationVo> list = jiajiaMallShopProductInformationService.selectJiajiaMallShopProductInformationList(jiajiaMallShopProductInformation);
        return getDataTable(list);
    }

    /**
     * 导出商城产品信息列表
     */
    @RequiresPermissions("system:product:export")
    @Log(title = "商城产品信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        List<JiajiaMallShopProductInformationVo> list = jiajiaMallShopProductInformationService.selectJiajiaMallShopProductInformationList(jiajiaMallShopProductInformation);
        ExcelUtil<JiajiaMallShopProductInformationVo> util = new ExcelUtil<JiajiaMallShopProductInformationVo>(JiajiaMallShopProductInformationVo.class);
        return util.exportExcel(list, "商城产品信息数据");
    }

    /**
     * 新增商城产品信息
     */
    @GetMapping("/add")
    public String add( ModelMap mmap)
    {
        ShiroUtils.getUserId();
        mmap.put("","");
        return prefix + "/add";
    }

    /**
     * 新增保存商城产品信息
     */
    @RequiresPermissions("system:product:add")
    @Log(title = "商城产品信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        return toAjax(jiajiaMallShopProductInformationService.insertJiajiaMallShopProductInformation(jiajiaMallShopProductInformation));
    }

    /**
     * 修改商城产品信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        JiajiaMallShopProductInformationVo jiajiaMallShopProductInformation = jiajiaMallShopProductInformationService.selectJiajiaMallShopProductInformationById(id);
        mmap.put("jiajiaMallShopProductInformation", jiajiaMallShopProductInformation);
        List<JiajiaMallProductType> list = jiajiaMallProductTypeService.selectJiajiaMallProductTypeList(new JiajiaMallProductType());

        mmap.put("productTypeList", list);

        JiajiaMallProductLevel jiajiaMallProductLevel=new JiajiaMallProductLevel();
        jiajiaMallProductLevel.setTypeId(jiajiaMallShopProductInformation.getTypeId());
        List<JiajiaMallProductLevelVo> list1 = jiajiaMallProductLevelService.selectJiajiaMallProductLevelList(jiajiaMallProductLevel);
        mmap.put("productLevelList", list1);
        return prefix + "/edit";
    }

    /**
     * 修改保存商城产品信息
     */
    @RequiresPermissions("system:product:edit")
    @Log(title = "商城产品信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(JiajiaMallShopProductInformation jiajiaMallShopProductInformation)
    {
        return toAjax(jiajiaMallShopProductInformationService.updateJiajiaMallShopProductInformation(jiajiaMallShopProductInformation));
    }

    /**
     * 删除商城产品信息
     */
    @RequiresPermissions("system:product:remove")
    @Log(title = "商城产品信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(jiajiaMallShopProductInformationService.deleteJiajiaMallShopProductInformationByIds(ids));
    }
}
